package wicket;

import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.PasswordTextField;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.PropertyModel;

import wicket.hibernate.HbPersonDAO;

public class ConnexionForm extends Form {
	private static final long serialVersionUID = 1L;
	private Person person = new Person();
	
	public ConnexionForm(String id) {
		super(id);
		
		PropertyModel nameProperty = new PropertyModel(person, "name");
		TextField nameTextField = new TextField("name", nameProperty);
		this.add(nameTextField);
		
		PropertyModel passwordProperty = new PropertyModel(person, "password");
		PasswordTextField passwordTextField = new PasswordTextField("password", passwordProperty);
		this.add(passwordTextField);
	}
	
	@Override
	protected void onSubmit(){
		HbPersonDAO personDAO = new HbPersonDAO();
		Person pers = personDAO.getPerson(person);
		if (pers != null){
			WicketHomePage.setSessionActive(true);
			getWebPage().get("contentPanel").replaceWith(new ListPanel("contentPanel"));
		}
	}

	public void setPerson(Person person) {
		this.person = person;
	}

	public Person getPerson() {
		return person;
	}

}
